package com.csoa.community.requests;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;

import com.csoa.community.bean.OfficialDocBean;
import com.csoa.community.net.ErrorMsg;
import com.csoa.community.singletons.GlobalVars;
import com.csoa.community.utils.Json;
import com.csoa.community.utils.StringUtils;

public class OffDocSearchRequest extends AbstractRequest {

	public List<OfficialDocBean> officialDocs;
	
	public OffDocSearchRequest(String readType,List<BasicNameValuePair> requestValues) {
		super(readType.equals(GlobalVars.READ_TYPE_TO_BE_READ)?OFFICIAL_DOC_SEARCH_BE_READ_METHOD:OFFICIAL_DOC_SEARCH_HAVE_READ_METHOD, requestValues);
	}

	

	@Override
	protected void parseRemaingInfo(String json) throws ErrorMsg, JSONException {
		if(!StringUtils.isEmpty(json)) {
			String strJson = "{value:"+json +"}";
			Json jsonOffis = new Json(strJson);
			officialDocs = new ArrayList<OfficialDocBean>();
			
			fillOfficialDocList(jsonOffis,officialDocs);
		}
	}
	
	
	public void fillOfficialDocList(Json json, List<OfficialDocBean> officialDocs) {
		Json[] jsons = json.getJsonArray("value");
		if(jsons != null) {
			for (int i=0;i<jsons.length;i++) {
				OfficialDocBean official = new OfficialDocBean();
				official.orderBy = jsons[i].getString("OrderBy");
				official.ID = jsons[i].getString("ID");
				official.RID = jsons[i].getString("RID");
				official.sendDate = jsons[i].getString("SendDate");
				official.title = jsons[i].getString("Title");
				official.ImportGrade = jsons[i].getString("ImportGrade");
				official.isRead = false;
				officialDocs.add(official);
			}
		}
		
		
	}
	
	
	
}
